package com.atguigu.service.Impl;

import com.atguigu.dao.BaseDao;
import com.atguigu.service.BaseService;
import com.atguigu.util.CastUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @title：
 * @author：Yu
 * @create：2023-02-03 17:34
 * @description：
 */
public abstract class BaseServiceImpl<T> implements BaseService<T> {
    public abstract BaseDao<T> getBaseDao();

    @Override
    public PageInfo<T> findPage(Map<String, Object> filters) {
        int pageNum = CastUtil.castInt(filters.get("pageNum"), 1);
        int pageSize = CastUtil.castInt(filters.get("pageSize"), 3);
        PageHelper.startPage(pageNum, pageSize);
        List<T> page = getBaseDao().findPage(filters);
        return new PageInfo<T>(page, 3);
    }

    @Override
    public void insert(T t) {
        getBaseDao().insert(t);
    }

    @Override
    public T findById(Serializable id) {
        return getBaseDao().findById(id);
    }

    @Override
    public void update(T t) {
        getBaseDao().update(t);
    }

    @Override
    public void delete(Serializable id) {
        getBaseDao().delete(id);
    }
}
